package com.lagou.bean;

import lombok.Data;
import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

@Data
public class ScoreBeanSort implements WritableComparable<ScoreBeanSort> {
    private Integer index;
    private Integer score;

    public ScoreBeanSort(Integer integer, Integer integer1) {
        this.index = integer;
        this.score = integer1;
    }



    @Override
    public int compareTo(ScoreBeanSort o) {
        if (score > o.getScore()) {
            return 1;
        } else if (score < o.getScore() ) {
            return -1;
        } else {
            return 0;
        }

    }

    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeInt(index);
        dataOutput.writeInt(score);

    }

    @Override
    public void readFields(DataInput dataInput) throws IOException {
        this.index = dataInput.readInt();
        this.score = dataInput.readInt();

    }

    @Override
    public String toString() {
        return
                 index + "\t" +
                 score ;
    }
}
